package top.ahzy.seobench.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ahzy.seobench.config.JWTConfig;
import top.ahzy.seobench.model.entity.User;
import top.ahzy.seobench.result.Result;
import top.ahzy.seobench.service.ConfigDataService;
import top.ahzy.seobench.util.JwtUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

@RestController
@RequestMapping("/configData")
@Api(tags = "配置数据模块")
public class ConfigDataController {

    @Autowired
    private ConfigDataService configDataService;

    @GetMapping()
    @ApiOperation(value = "获取配置信息", notes = "")
    public Result<String> getDetail(HttpServletRequest request) {
        String token = request.getHeader(JWTConfig.tokenHeader);
        User user = JwtUtil.parseAccessToken(token);
        return configDataService.getDetail(user.getId());
    }

    @PutMapping("/edit")
    @ApiOperation(value = "更新配置信息", notes = "")
    public Result<String> edit(HttpServletRequest request, @RequestBody String detail) {
        String token = request.getHeader(JWTConfig.tokenHeader);
        User user = JwtUtil.parseAccessToken(token);
        return configDataService.edit(user.getId(),detail);
    }

}
